#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    LL res = 0;
    int T;
    int n, m;
    scanf("%d", &T);
    while(T--){
        scanf("%d%d", &n, &m);
        LL res = ((LL)m * m + (LL)m * n + (LL)m * n * n - m) / 2;
        printf("%lld\n",  res);
    }

    return 0;
}